import numpy as np
import pandas as pd
from sympy.logic.boolalg import Boolean

import bean.param as param
import BFPred as BFPred


def analysis(req:param.AnalysisReq, data: param.PreEvaluateData):
    print("analysis 网络神经模型开始,code:{}".format(req.bridgeCode))
    bridgeType=req.bridgeType
    # 转换成 千米
    mainSpanLilometre = float(data.mainSpan) / 1000
    if bridgeType == 1:
        # 梁桥
        param = np.array([[int(data.girderType), mainSpanLilometre*1000]])  # 主跨长度单位还原为 米

        frequency, damping_ratio = BFPred.girder_bridge_pred(param)

        print("analysis 网络神经模型结束,code:{}".format(req.bridgeCode))
        return pd.DataFrame({'振型阶数': [1, 2, 3], \
                             '固有频率(Hz)': frequency, \
                             '振型阻尼比': damping_ratio})

    elif bridgeType == 3:
        # 斜拉桥
        # 转换成百米
        towerHeightHectoeter = float(data.towerHeight) / 100
        param = np.array([[mainSpanLilometre,
                           #车道数 不使用了
                           0,
                           # 桥面宽度 不使用了
                           0,
                           #主梁类型
                           trans_value("钢箱梁"==data.mainBeamType),
                           trans_value("钢桁梁"==data.mainBeamType),
                           trans_value("钢混组合梁"==data.mainBeamType),
                           trans_value("混凝土梁"==data.mainBeamType),
                           float(data.towerNumber),
                           towerHeightHectoeter]])
        frequency, damping_ratio = BFPred.Cable_stayed_bridge_pred(param)
        elements_list = [elem.item() for elem in frequency]
        print("analysis 网络神经模型结束,code:{}".format(req.bridgeCode))
        return pd.DataFrame({'振型阶数': [1, 2, 3], \
                             '固有频率(Hz)': elements_list, \
                             '振型阻尼比':damping_ratio})


def trans_value(condition:bool):
    if condition:
        return 1
    else:
        return 0


